import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBWorkTaiModel/YBCityNameModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBWorkTaiModel/YBMiShuTongListModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBNetWorkModule/YBWorkTaiNetWork/YBBaseWorkTaiNetWorkManager.dart';
import 'package:common_utils/common_utils.dart';

//秘书通 -商机库-列表
class YBMiShuTongShangJuKuProvider with ChangeNotifier{

  List<YBMiShuTongListModel> _shangJiKuList = List<YBMiShuTongListModel>();

  List<YBMiShuTongListModel> get shangJiKuModelList => _shangJiKuList;

  RefreshController _easyRefreshController = RefreshController();

  RefreshController get easyfresh => _easyRefreshController;

  int current = 1;

  void getRefresh(String address,String requestTag){
    current = 1;
    getMiShuTongShangJuKuDataList(current, address:address,requestTag:requestTag);
  }

  void loadData(String address,String requestTag){
    current++;
    getMiShuTongShangJuKuDataList(current, address:address,requestTag:requestTag);
  }

  void getMiShuTongShangJuKuDataList(int page,{String address,String requestTag}){

    Map<String, dynamic> parmMap = Map<String,dynamic>();


    parmMap['pageSize'] = 20;
    parmMap['pageNo'] = page;


    if (address != null) {
       parmMap['address'] = address;
    }

    if (requestTag != null) {
      parmMap['requestTag'] = requestTag;
    }

    if (requestTag != null) {
      parmMap['requestTag'] = requestTag;
    }

    YBBaseWorkTaiNetWork.workTaiMiShuTongShangJiKuList(parmMap,success: (data){
      print("-秘书通----商机库列表-$data-");
      if (page == 1) {
        _shangJiKuList.clear();
      }
      int totalPage = data['totalPage'];
      if (totalPage == page) {
        _easyRefreshController.loadComplete();
        _easyRefreshController.refreshCompleted();
      }else{
        _easyRefreshController.refreshCompleted();
        _easyRefreshController.loadComplete();
      }

      List resultList = data['result'];
      if (!ObjectUtil.isEmptyList(resultList)) {
        _shangJiKuList.addAll(resultList.map((e){
          return YBMiShuTongListModel.fromJson(e);
        }).toList());
        print("-秘书通----商机库列表-$_shangJiKuList-");
        notifyListeners();
      }
    },fail: (error){
      print("-秘书通----商机库列表error-$error-");
    });
  }

}

//秘书通 -商机库-详情页
class YBMiShuTongShangJiKuDetailProvider with ChangeNotifier{

  YBMiShuTongListModel shangJiKuModel;


  void getMiShuTongShangJuKuDataList({String requestCode,String sysCode}){

    Map<String, dynamic> parmMap = Map<String,dynamic>();


    if (sysCode != null) {
      parmMap['sysCode'] = sysCode;
    }

    if (requestCode != null) {
      parmMap['requestCode'] = requestCode;
    }

    YBBaseWorkTaiNetWork.workTaiMiShuTongShangJiKuDetail(parmMap,success: (data){
      print("-秘书通----商机库详情页-$data-");
      shangJiKuModel = YBMiShuTongListModel.fromJson(data);
      notifyListeners();
    },fail: (error){
      print("-秘书通----商机库详情页error-$error-");
    });
  }
}


//秘书通 -商机库-详情页
class YBMiShuTongShangJiKuDetailQiangDuoShangjiProvider with ChangeNotifier{

  bool shangJiKuQiangDuoStr;


  void getMiShuTongShangJuKuDataList({String requestCode,String sysCode}){

    Map<String, dynamic> parmMap = Map<String,dynamic>();


    if (sysCode != null) {
      parmMap['sysCode'] = sysCode;
    }

    if (requestCode != null) {
      parmMap['requestCode'] = requestCode;
    }

    YBBaseWorkTaiNetWork.workTaiMiShuTongShangJiKuDetailQiangDuoShangJi(parmMap,success: (data){
      print("-秘书通----商机库详情页抢夺商机--$data-");
      shangJiKuQiangDuoStr = data;
      notifyListeners();
    },fail: (error){
      print("-秘书通----商机库详情页error抢夺商机--$error-");
    });
  }
}


//秘书通-商机库-筛选(全国，全部事务)
class YBMiShuTongShangJiKuShaiXuanProvider with ChangeNotifier{

  List<YBCityNameModel> quanGuoCityNameList = List<YBCityNameModel>();

  List<String> transcationList = List<String>();

  void getMiShuTongShangJuKuShaiXuan(){

    Map<String, dynamic> parmMap = Map<String,dynamic>();

    YBBaseWorkTaiNetWork.workTaiMiShuTongShangJiKuShuaiXuanData(parmMap,success: (data){
      print("-秘书通----商机库筛选库--$data-");

      List areaList = data['area'];
      if (!ObjectUtil.isEmptyList(areaList)) {
         quanGuoCityNameList.addAll(
           areaList.map((data){
             return YBCityNameModel.fromJson(data);
           }).toList());
      }

      List transiteList = data['transaction'];
      if (!ObjectUtil.isEmptyList(transiteList)) {
         transcationList.addAll(
           transiteList.map((e) => "$e").toList(),
         );
      }


      notifyListeners();
    },fail: (error){
      print("-秘书通----商机库详情页error抢夺商机--$error-");
    });
  }
}

//秘书通-已获商机-列表
class YBMiShuTongYiHuoShangJiManangerListProvider with ChangeNotifier{

  List<YBMiShuTongListModel> _shangJiManagerList = List<YBMiShuTongListModel>();

  List<YBMiShuTongListModel> get shangJiManangerModelList => _shangJiManagerList;

  RefreshController _easyRefreshController = RefreshController();

  RefreshController get easyfresh => _easyRefreshController;

  int current = 1;

  void getRefresh({String isSecretary}){
    current = 1;
    getMiShuTongShangJuKuDataList(current, isSecretary:isSecretary);
  }

  void loadData({String isSecretary}){
    current++;
    getMiShuTongShangJuKuDataList(current, isSecretary:isSecretary);
  }

  void getMiShuTongShangJuKuDataList(int page,{String isSecretary}){

    Map<String, dynamic> parmMap = Map<String,dynamic>();


    parmMap['pageSize'] = 20;
    parmMap['pageNo'] = page;


    if (isSecretary != null) {
      parmMap['isSecretary'] = isSecretary;
    }


    YBBaseWorkTaiNetWork.workTaiMiShuTongShangJiManager(parmMap,success: (data){
      print("-秘书通----商机库列表-$data-");
      if (page == 1) {
        _shangJiManagerList.clear();
      }
      int totalPage = data['totalPage'];
      if (totalPage == page) {
        _easyRefreshController.loadComplete();
        _easyRefreshController.refreshCompleted();
      }else{
        _easyRefreshController.refreshCompleted();
        _easyRefreshController.loadComplete();
      }

      List resultList = data['result'];
      if (!ObjectUtil.isEmptyList(resultList)) {
        _shangJiManagerList.addAll(resultList.map((e){
          return YBMiShuTongListModel.fromJson(e);
        }).toList());
        print("-秘书通----商机库列表-$_shangJiManagerList-");
        notifyListeners();
      }
    },fail: (error){
      print("-秘书通----商机库列表error-$error-");
    });
  }
}